package com.elock.intf.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elock.base.core.Page;
import com.elock.base.core.Pageable;
import com.elock.base.core.controller.BaseController;
import com.elock.base.core.controller.ResultMsg;
import com.elock.base.core.util.JsonUtils;
import com.elock.entity.Member;
import com.elock.intf.service.IntfMemberService;
import com.elock.service.CompanyInfoService;

/**
 * 用户
 * @author 仁德
 */
@Controller("intfMemberController")
@RequestMapping("/intf/member")
public class MemberController extends BaseController {

	@Resource(name = "intfMemberServiceImpl")
	private IntfMemberService intfMemberService;
	@Resource(name = "companyInfoServiceImpl")
	private CompanyInfoService companyInfoService;

	/**
	 * 列表数据
	 */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public @ResponseBody ResultMsg list_data(String username, String mobile, String name,
			String pinCode, Long saleOrgId, String startTime, String endTime,
			Integer memberType, Pageable pageable, ModelMap model) {

		Page<Map<String, Object>> page = intfMemberService.findPage(username,
				mobile,
				name,
				pinCode,
				saleOrgId,
				startTime,
				endTime,
				memberType,
				pageable);

		String jsonPage = JsonUtils.toJson(page);

		return success(jsonPage);
	}

	/**
	 * 更新
	 */
	@RequestMapping(value = "/update_bus", method = RequestMethod.POST)
	public @ResponseBody ResultMsg update_bus(String companycode, Member member,
			String[] roleName, String saleOrgSn, HttpServletRequest request,
			ModelMap model) {

		// 更新用户
		intfMemberService.updateb(companycode, member, saleOrgSn, roleName);
		return success();
	}

	/**
	 * 更新
	 */
	@RequestMapping(value = "/update_terminal", method = RequestMethod.POST)
	public @ResponseBody ResultMsg update_terminal(String companycode, Member member,
			String saleOrgSn, String[] terminalNum, HttpServletRequest request,
			ModelMap model) {

		// 更新用户
		intfMemberService.updatet(companycode, member, saleOrgSn, terminalNum);
		return success();
	}

	@RequestMapping(value = "/delete_bus", method = RequestMethod.POST)
	public @ResponseBody ResultMsg delete_bus(String companycode, String username) {

		intfMemberService.deleteMember(companycode, username, null, 0);
		return success();
	}

	@RequestMapping(value = "/delete_terminal", method = RequestMethod.POST)
	public @ResponseBody ResultMsg delete_terminal(String companycode, String pinCode,
			ModelMap model) {

		intfMemberService.deleteMember(companycode, null, pinCode, 1);
		return success();
	}

}
